﻿using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.BrowserApp
{
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();

            // 注册事件总线
            Event.NCL.NCLEventBus.Register(RemoteEventProxy.Instance);
            Event.Core.CoreEventBus.Register(RemoteEventProxy.Instance);

            UIContext.Current.RootViewContainer = this._ctlViewContainer;

            ShowsNavigationUI = false;

            CPPEI.Coolzon.UI.Views.LoginView loginView = new UI.Views.LoginView(CZEnvironment.UserAccount,
                CZEnvironment.UserPassword);
            loginView.Close += loginView_Close;
            SetContent(loginView);
            loginView.Active();
        }

        void loginView_Close(View view, bool isCancel)
        {
            CPPEI.Coolzon.UI.Views.LoadingView syncView = new UI.Views.LoadingView(CZEnvironment.Solution,
                CZEnvironment.GetSolutionFilePath(CZEnvironment.Solution),
                CZEnvironment.GetSolutionDirectoryPath(CZEnvironment.Solution));
            syncView.Close += syncView_Close;
            SetContent(syncView);
            syncView.Active();
        }

        private void SetContent(object content)
        {
            //this.Content = content;
            this._ctlViewContainer.SwitchView((View)content);
        }

        void syncView_Close(UI.View view, bool isCancel)
        {
            UI.Views.LoadingView syncView = view as UI.Views.LoadingView;
            CPPEI.Coolzon.BrowserApp.Views.MainView mainView = new Views.MainView(syncView.LoadedSolution);
            mainView.Close += mainView_Close;
            SetContent(mainView);
            mainView.Active();
        }

        void mainView_Close(UI.View view, bool isCancel)
        {
        }
    }
}
